package org.teamswift.crow.rbac.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import org.teamswift.crow.rbac.entity.CrowAuthority;

import java.util.List;
import java.util.Optional;

@Repository
public interface CrowAuthorityRepository extends JpaRepository<CrowAuthority, Integer>, JpaSpecificationExecutor<CrowAuthority> {

    List<CrowAuthority> findAllByRoleIdIn(List<Integer> roleId);

    List<CrowAuthority> findAllByRoleId(Integer roleId);

    List<CrowAuthority> findAllByRoleIdOrderByPermissionResourceAscActionAsc(Integer roleId);

    Optional<CrowAuthority> findByRoleIdAndPermissionResource(Integer roleId, String permissionResource);

    List<CrowAuthority> findAllByRoleIdInAndPermissionResource(List<Integer> rolesId, String permissionResource);

    @Modifying
    void deleteAllByRoleId(Integer roleId);

}
